/**
 * ajax请求
 * @param url
 * @param param
 * @returns
 */
function ajaxAction(url,param){
	var obj;
	$.ajax({
		   type: "POST",
		   url: url,
		   data: param,
		   async: false,
		   dataType: "json",
		   success: function(msg){
			   if(msg){
				  obj=msg;
			   }
		   },
		   error:function(XMLHttpRequest,textStatus,errorThrown){
			   alert("请求异常");
		   }
	});
	return obj;
}
/**
 * 成功提示消息
 * @param msg
 */
function showSuccessToast(msg) {
    $().toastmessage('showToast', {
        text     : msg,
        sticky   : false,
        position : 'top-center',
        type     : 'success',
        closeText: '',
        close    : function () {
            console.log("toast is closed ...");
        }
    });

}
/**
 * 失败提示消息
 * @param msg
 */
function showErrorToast(msg) {
    $().toastmessage('showToast', {
        text     : msg,
        sticky   : false,
        position : 'top-center',
        type     : 'error',
        closeText: '',
        close    : function () {
            console.log("toast is closed ...");
        }
    });

}
/**
 * checkBox全选
 */
function checkAll(sender){
	var obj=$(sender);
	var checkboxAll=$("#tbody").find(":checkbox");
	var checkboxSpan=$("#tbody").find("span");
	if(obj.attr("checked")){
		checkboxAll.attr("checked",true);
		checkboxSpan.addClass("checked")
	}else{
		checkboxAll.attr("checked",false);
		checkboxSpan.removeClass("checked")
	}
}
/**
 * 获取checkbox选中所有的id
 */
function getIds(){
	var ckb = $("#tbody").find(":checkbox:checked");
	if(ckb.length>0){
		var dics = "";
		for(var i=0; i<ckb.length; i++){
			if(i>0){
				dics+=',';
			}
			dics = dics+ckb[i].value;
		}
		return dics;
	}
	alert("请选择一条数据");
	return "";
}

/**
 * 获取checkbox选中所有的id
 */
function getOneId(){
	var ckb = $("#tbody").find(":checkbox:checked");
	if(ckb.length==1){
		return ckb[0].value;
	}
	alert("请选择一条数据");
	return "";
}
/**
 * 时间格式化
 * @param value
 * @returns
 */
function formatDate(value){
	if(value!=null){
		var date = new Date(value);
		if( date.getHours() == 0)
			return  date.format("yyyy-MM-dd");
		else
			return  date.format("yyyy-MM-dd hh:mm:ss");
	}
	return "";
}

Date.prototype.format = function(format){ 
	var o = { 
	"M+" : this.getMonth()+1, //month 
	"d+" : this.getDate(), //day 
	"h+" : this.getHours(), //hour 
	"m+" : this.getMinutes(), //minute 
	"s+" : this.getSeconds(), //second 
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
	"S" : this.getMilliseconds() //millisecond 
	} 
	
	if(/(y+)/.test(format)) { 
	format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
	} 
	
	for(var k in o) { 
	if(new RegExp("("+ k +")").test(format)) { 
	format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
	} 
	} 
	return format; 
} 

function isString(str){
	return (typeof str=='string')&&str.constructor==String; 
}

function isNull(obj){
	return (obj==null||obj==undefined||obj==""||obj.length==0);
}

function layMsg(msg,time){
	 layer.msg(msg, {
	        time: time, //20s后自动关闭
	        btn: ['明白了', '知道了']
	      });
}